package com.ztjc.day03_arrayadapter;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

/**
 * ArrayAdapter的使用
 */
public class MainActivity extends Activity {

    private ListView lvList;
    private List<String> strings;
    private ArrayAdapter<String> arrayAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        lvList = (ListView) findViewById(R.id.lv_list);

        createData();
    }

    /**
     * 创建虚拟数据
     */
    private void createData() {
        strings = new ArrayList<>();
        for (int i = 0; i < 20; i ++) {
            strings.add("列表项：" + i);
        }
        arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, strings);
        lvList.setAdapter(arrayAdapter);
    }

}
